package org.jivesoftware.smackx.muc;

import com.easemob.util.EMLog;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.PacketInterceptor;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Message.Type;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.NodeInformationProvider;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.packet.DiscoverItems.Item;
import org.jivesoftware.smackx.packet.MUCAdmin;
import org.jivesoftware.smackx.packet.MUCAdmin.Item;
import org.jivesoftware.smackx.packet.MUCCreatePresence;
import org.jivesoftware.smackx.packet.MUCInitialPresence;
import org.jivesoftware.smackx.packet.MUCJoinPresence;
import org.jivesoftware.smackx.packet.MUCOwner;
import org.jivesoftware.smackx.packet.MUCOwner.Destroy;
import org.jivesoftware.smackx.packet.MUCOwner.Item;
import org.jivesoftware.smackx.packet.MUCUser;
import org.jivesoftware.smackx.packet.MUCUser.Decline;
import org.jivesoftware.smackx.packet.MUCUser.Invite;
import org.jivesoftware.smackx.packet.MUCUser.Item;
import org.jivesoftware.smackx.packet.MUCUser.Status;

public class MultiUserChat
{
  private static final String discoNamespace = "http://jabber.org/protocol/muc";
  private static final String discoNode = "http://jabber.org/protocol/muc#rooms";
  private static Map<Connection, List<String>> joinedRooms = new WeakHashMap();
  private Connection connection;
  private String room;
  private String subject;
  private String nickname = null;
  private boolean joined = false;
  private Map<String, Presence> occupantsMap = new ConcurrentHashMap();
  private final List<InvitationRejectionListener> invitationRejectionListeners = new ArrayList();
  private final List<SubjectUpdatedListener> subjectUpdatedListeners = new ArrayList();
  private final List<UserStatusListener> userStatusListeners = new ArrayList();
  private final List<ParticipantStatusListener> participantStatusListeners = new ArrayList();
  private PacketFilter presenceFilter;
  private List<PacketInterceptor> presenceInterceptors = new ArrayList();
  private PacketFilter messageFilter;
  private RoomListenerMultiplexor roomListenerMultiplexor;
  private ConnectionDetachedPacketCollector messageCollector;
  private List<PacketListener> connectionListeners = new ArrayList();

  static
  {
    Connection.addConnectionCreationListener(new ConnectionCreationListener()
    {
      public void connectionCreated(final Connection paramAnonymousConnection)
      {
        ServiceDiscoveryManager.getInstanceFor(paramAnonymousConnection).addFeature("http://jabber.org/protocol/muc");
        ServiceDiscoveryManager.getInstanceFor(paramAnonymousConnection).setNodeInformationProvider("http://jabber.org/protocol/muc#rooms", new NodeInformationProvider()
        {
          public List<DiscoverItems.Item> getNodeItems()
          {
            ArrayList localArrayList = new ArrayList();
            Iterator localIterator = MultiUserChat.getJoinedRooms(paramAnonymousConnection);
            while (localIterator.hasNext())
              localArrayList.add(new DiscoverItems.Item((String)localIterator.next()));
            return localArrayList;
          }

          public List<String> getNodeFeatures()
          {
            return null;
          }

          public List<DiscoverInfo.Identity> getNodeIdentities()
          {
            return null;
          }

          public List<PacketExtension> getNodePacketExtensions()
          {
            return null;
          }
        });
      }
    });
  }

  public MultiUserChat(Connection paramConnection, String paramString)
  {
    this.connection = paramConnection;
    this.room = paramString.toLowerCase();
    init();
  }

  public static boolean isServiceEnabled(Connection paramConnection, String paramString)
  {
    try
    {
      DiscoverInfo localDiscoverInfo = ServiceDiscoveryManager.getInstanceFor(paramConnection).discoverInfo(paramString);
      return localDiscoverInfo.containsFeature("http://jabber.org/protocol/muc");
    }
    catch (XMPPException localXMPPException)
    {
      localXMPPException.printStackTrace();
    }
    return false;
  }

  private static Iterator<String> getJoinedRooms(Connection paramConnection)
  {
    List localList = (List)joinedRooms.get(paramConnection);
    if (localList != null)
      return localList.iterator();
    return new ArrayList().iterator();
  }

  public static Iterator<String> getJoinedRooms(Connection paramConnection, String paramString)
  {
    try
    {
      ArrayList localArrayList = new ArrayList();
      DiscoverItems localDiscoverItems = ServiceDiscoveryManager.getInstanceFor(paramConnection).discoverItems(paramString, "http://jabber.org/protocol/muc#rooms");
      Iterator localIterator = localDiscoverItems.getItems();
      while (localIterator.hasNext())
        localArrayList.add(((DiscoverItems.Item)localIterator.next()).getEntityID());
      return localArrayList.iterator();
    }
    catch (XMPPException localXMPPException)
    {
      localXMPPException.printStackTrace();
    }
    return new ArrayList().iterator();
  }

  public static RoomInfo getRoomInfo(Connection paramConnection, String paramString)
    throws XMPPException
  {
    DiscoverInfo localDiscoverInfo = ServiceDiscoveryManager.getInstanceFor(paramConnection).discoverInfo(paramString);
    return new RoomInfo(localDiscoverInfo);
  }

  public static Collection<String> getServiceNames(Connection paramConnection)
    throws XMPPException
  {
    ArrayList localArrayList = new ArrayList();
    ServiceDiscoveryManager localServiceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(paramConnection);
    DiscoverItems localDiscoverItems = localServiceDiscoveryManager.discoverItems(paramConnection.getServiceName());
    Iterator localIterator = localDiscoverItems.getItems();
    while (localIterator.hasNext())
    {
      DiscoverItems.Item localItem = (DiscoverItems.Item)localIterator.next();
      try
      {
        DiscoverInfo localDiscoverInfo = localServiceDiscoveryManager.discoverInfo(localItem.getEntityID());
        if (localDiscoverInfo.containsFeature("http://jabber.org/protocol/muc"))
          localArrayList.add(localItem.getEntityID());
      }
      catch (XMPPException localXMPPException)
      {
      }
    }
    return localArrayList;
  }

  public static Collection<HostedRoom> getHostedRooms(Connection paramConnection, String paramString)
    throws XMPPException
  {
    ArrayList localArrayList = new ArrayList();
    ServiceDiscoveryManager localServiceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(paramConnection);
    DiscoverItems localDiscoverItems = localServiceDiscoveryManager.discoverItems(paramString);
    Iterator localIterator = localDiscoverItems.getItems();
    while (localIterator.hasNext())
      localArrayList.add(new HostedRoom((DiscoverItems.Item)localIterator.next()));
    return localArrayList;
  }

  public static Collection<HostedRoom> getPublicRooms(Connection paramConnection, String paramString1, String paramString2)
    throws XMPPException
  {
    ArrayList localArrayList = new ArrayList();
    ServiceDiscoveryManager localServiceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(paramConnection);
    DiscoverItems localDiscoverItems = localServiceDiscoveryManager.discoverItems(paramString1, paramString2);
    Iterator localIterator = localDiscoverItems.getItems();
    while (localIterator.hasNext())
      localArrayList.add(new HostedRoom((DiscoverItems.Item)localIterator.next()));
    return localArrayList;
  }

  public String getRoom()
  {
    return this.room;
  }

  public synchronized void create(String paramString)
    throws XMPPException
  {
    if ((paramString == null) || (paramString.equals("")))
      throw new IllegalArgumentException("Nickname must not be null or blank.");
    if (this.joined)
      throw new IllegalStateException("Creation failed - User already joined the room.");
    Presence localPresence1 = new Presence(Presence.Type.available);
    localPresence1.setTo(this.room + "/" + paramString);
    localPresence1.addExtension(new MUCInitialPresence());
    localPresence1.addExtension(new MUCCreatePresence());
    Object localObject2 = this.presenceInterceptors.iterator();
    while (((Iterator)localObject2).hasNext())
    {
      localObject1 = (PacketInterceptor)((Iterator)localObject2).next();
      ((PacketInterceptor)localObject1).interceptPacket(localPresence1);
    }
    Object localObject1 = new AndFilter(new PacketFilter[] { new FromMatchesFilter(this.room + "/" + paramString), new PacketTypeFilter(Presence.class) });
    localObject2 = this.connection.createPacketCollector((PacketFilter)localObject1);
    this.connection.sendPacket(localPresence1);
    Presence localPresence2 = (Presence)((PacketCollector)localObject2).nextResult(SmackConfiguration.getPacketReplyTimeout());
    ((PacketCollector)localObject2).cancel();
    if (localPresence2 == null)
      throw new XMPPException("No response from server.");
    if (localPresence2.getError() != null)
      throw new XMPPException(localPresence2.getError());
    this.nickname = paramString;
    this.joined = true;
    userHasJoined();
    MUCUser localMUCUser = getMUCUserExtension(localPresence2);
    if ((localMUCUser != null) && (localMUCUser.getStatus() != null) && ("201".equals(localMUCUser.getStatus().getCode())))
      return;
    leave();
    throw new XMPPException("Creation failed - Missing acknowledge of room creation.");
  }

  public void join(String paramString)
    throws XMPPException
  {
    join(paramString, null, null, SmackConfiguration.getPacketReplyTimeout());
  }

  public void join(String paramString1, String paramString2)
    throws XMPPException
  {
    join(paramString1, paramString2, null, SmackConfiguration.getPacketReplyTimeout());
  }

  public synchronized void join(String paramString1, String paramString2, DiscussionHistory paramDiscussionHistory, long paramLong)
    throws XMPPException
  {
    if ((paramString1 == null) || (paramString1.equals("")))
      throw new IllegalArgumentException("Nickname must not be null or blank.");
    if (this.joined)
      leave();
    Presence localPresence1 = new Presence(Presence.Type.available);
    localPresence1.setTo(this.room + "/" + paramString1);
    MUCInitialPresence localMUCInitialPresence = new MUCInitialPresence();
    if (paramString2 != null)
      localMUCInitialPresence.setPassword(paramString2);
    if (paramDiscussionHistory != null)
      localMUCInitialPresence.setHistory(paramDiscussionHistory.getMUCHistory());
    localPresence1.addExtension(localMUCInitialPresence);
    MUCJoinPresence localMUCJoinPresence = new MUCJoinPresence();
    localPresence1.addExtension(localMUCJoinPresence);
    Object localObject2 = this.presenceInterceptors.iterator();
    while (((Iterator)localObject2).hasNext())
    {
      localObject1 = (PacketInterceptor)((Iterator)localObject2).next();
      ((PacketInterceptor)localObject1).interceptPacket(localPresence1);
    }
    Object localObject1 = new AndFilter(new PacketFilter[] { new FromMatchesFilter(this.room + "/" + paramString1), new PacketTypeFilter(Presence.class) });
    localObject2 = null;
    Presence localPresence2;
    try
    {
      localObject2 = this.connection.createPacketCollector((PacketFilter)localObject1);
      this.connection.sendPacket(localPresence1);
      localPresence2 = (Presence)((PacketCollector)localObject2).nextResult(paramLong);
    }
    catch (IllegalStateException localIllegalStateException)
    {
      throw new XMPPException("not connected to server");
    }
    finally
    {
      if (localObject2 != null)
        ((PacketCollector)localObject2).cancel();
    }
    if (localPresence2 == null)
      throw new XMPPException("No response from server.");
    if (localPresence2.getError() != null)
      throw new XMPPException(localPresence2.getError());
    this.nickname = paramString1;
    this.joined = true;
    userHasJoined();
  }

  public boolean isJoined()
  {
    return this.joined;
  }

  public synchronized void leave()
  {
    if (!this.joined)
      return;
    Presence localPresence = new Presence(Presence.Type.unavailable);
    localPresence.setTo(this.room + "/" + this.nickname);
    Iterator localIterator = this.presenceInterceptors.iterator();
    while (localIterator.hasNext())
    {
      PacketInterceptor localPacketInterceptor = (PacketInterceptor)localIterator.next();
      localPacketInterceptor.interceptPacket(localPresence);
    }
    this.connection.sendPacket(localPresence);
    this.occupantsMap.clear();
    this.nickname = null;
    this.joined = false;
    userHasLeft();
  }

  public Form getConfigurationForm()
    throws XMPPException
  {
    MUCOwner localMUCOwner = new MUCOwner();
    localMUCOwner.setTo(this.room);
    localMUCOwner.setType(IQ.Type.GET);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localMUCOwner.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localMUCOwner);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
    return Form.getFormFrom(localIQ);
  }

  public void sendConfigurationForm(Form paramForm)
    throws XMPPException
  {
    MUCOwner localMUCOwner = new MUCOwner();
    localMUCOwner.setTo(this.room);
    localMUCOwner.setType(IQ.Type.SET);
    localMUCOwner.addExtension(paramForm.getDataFormToSend());
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localMUCOwner.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localMUCOwner);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
  }

  public Form getRegistrationForm()
    throws XMPPException
  {
    Registration localRegistration = new Registration();
    localRegistration.setType(IQ.Type.GET);
    localRegistration.setTo(this.room);
    AndFilter localAndFilter = new AndFilter(new PacketFilter[] { new PacketIDFilter(localRegistration.getPacketID()), new PacketTypeFilter(IQ.class) });
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localAndFilter);
    this.connection.sendPacket(localRegistration);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getType() == IQ.Type.ERROR)
      throw new XMPPException(localIQ.getError());
    return Form.getFormFrom(localIQ);
  }

  public void sendRegistrationForm(Form paramForm)
    throws XMPPException
  {
    Registration localRegistration = new Registration();
    localRegistration.setType(IQ.Type.SET);
    localRegistration.setTo(this.room);
    localRegistration.addExtension(paramForm.getDataFormToSend());
    AndFilter localAndFilter = new AndFilter(new PacketFilter[] { new PacketIDFilter(localRegistration.getPacketID()), new PacketTypeFilter(IQ.class) });
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localAndFilter);
    this.connection.sendPacket(localRegistration);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getType() == IQ.Type.ERROR)
      throw new XMPPException(localIQ.getError());
  }

  public void destroy(String paramString1, String paramString2)
    throws XMPPException
  {
    MUCOwner localMUCOwner = new MUCOwner();
    localMUCOwner.setTo(this.room);
    localMUCOwner.setType(IQ.Type.SET);
    MUCOwner.Destroy localDestroy = new MUCOwner.Destroy();
    localDestroy.setReason(paramString1);
    localDestroy.setJid(paramString2);
    localMUCOwner.setDestroy(localDestroy);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localMUCOwner.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localMUCOwner);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
    this.occupantsMap.clear();
    this.nickname = null;
    this.joined = false;
    userHasLeft();
  }

  public void invite(String paramString1, String paramString2)
  {
    invite(new Message(), paramString1, paramString2);
  }

  public void invite(Message paramMessage, String paramString1, String paramString2)
  {
    paramMessage.setTo(this.room);
    MUCUser localMUCUser = new MUCUser();
    MUCUser.Invite localInvite = new MUCUser.Invite();
    localInvite.setTo(paramString1);
    localInvite.setReason(paramString2);
    localMUCUser.setInvite(localInvite);
    paramMessage.addExtension(localMUCUser);
    this.connection.sendPacket(paramMessage);
  }

  public static void decline(Connection paramConnection, String paramString1, String paramString2, String paramString3)
  {
    Message localMessage = new Message(paramString1);
    MUCUser localMUCUser = new MUCUser();
    MUCUser.Decline localDecline = new MUCUser.Decline();
    localDecline.setTo(paramString2);
    localDecline.setReason(paramString3);
    localMUCUser.setDecline(localDecline);
    localMessage.addExtension(localMUCUser);
    paramConnection.sendPacket(localMessage);
  }

  public static void addInvitationListener(Connection paramConnection, InvitationListener paramInvitationListener)
  {
    InvitationsMonitor.getInvitationsMonitor(paramConnection).addInvitationListener(paramInvitationListener);
  }

  public static void removeInvitationListener(Connection paramConnection, InvitationListener paramInvitationListener)
  {
    InvitationsMonitor.getInvitationsMonitor(paramConnection).removeInvitationListener(paramInvitationListener);
  }

  public void addInvitationRejectionListener(InvitationRejectionListener paramInvitationRejectionListener)
  {
    synchronized (this.invitationRejectionListeners)
    {
      if (!this.invitationRejectionListeners.contains(paramInvitationRejectionListener))
        this.invitationRejectionListeners.add(paramInvitationRejectionListener);
    }
  }

  public void removeInvitationRejectionListener(InvitationRejectionListener paramInvitationRejectionListener)
  {
    synchronized (this.invitationRejectionListeners)
    {
      this.invitationRejectionListeners.remove(paramInvitationRejectionListener);
    }
  }

  private void fireInvitationRejectionListeners(String paramString1, String paramString2)
  {
    InvitationRejectionListener[] arrayOfInvitationRejectionListener1;
    synchronized (this.invitationRejectionListeners)
    {
      arrayOfInvitationRejectionListener1 = new InvitationRejectionListener[this.invitationRejectionListeners.size()];
      this.invitationRejectionListeners.toArray(arrayOfInvitationRejectionListener1);
    }
    for (??? : arrayOfInvitationRejectionListener1)
      ???.invitationDeclined(paramString1, paramString2);
  }

  public void addSubjectUpdatedListener(SubjectUpdatedListener paramSubjectUpdatedListener)
  {
    synchronized (this.subjectUpdatedListeners)
    {
      if (!this.subjectUpdatedListeners.contains(paramSubjectUpdatedListener))
        this.subjectUpdatedListeners.add(paramSubjectUpdatedListener);
    }
  }

  public void removeSubjectUpdatedListener(SubjectUpdatedListener paramSubjectUpdatedListener)
  {
    synchronized (this.subjectUpdatedListeners)
    {
      this.subjectUpdatedListeners.remove(paramSubjectUpdatedListener);
    }
  }

  private void fireSubjectUpdatedListeners(String paramString1, String paramString2)
  {
    SubjectUpdatedListener[] arrayOfSubjectUpdatedListener1;
    synchronized (this.subjectUpdatedListeners)
    {
      arrayOfSubjectUpdatedListener1 = new SubjectUpdatedListener[this.subjectUpdatedListeners.size()];
      this.subjectUpdatedListeners.toArray(arrayOfSubjectUpdatedListener1);
    }
    for (??? : arrayOfSubjectUpdatedListener1)
      ???.subjectUpdated(paramString1, paramString2);
  }

  public void addPresenceInterceptor(PacketInterceptor paramPacketInterceptor)
  {
    this.presenceInterceptors.add(paramPacketInterceptor);
  }

  public void removePresenceInterceptor(PacketInterceptor paramPacketInterceptor)
  {
    this.presenceInterceptors.remove(paramPacketInterceptor);
  }

  public String getSubject()
  {
    return this.subject;
  }

  public String getReservedNickname()
  {
    try
    {
      DiscoverInfo localDiscoverInfo = ServiceDiscoveryManager.getInstanceFor(this.connection).discoverInfo(this.room, "x-roomuser-item");
      Iterator localIterator = localDiscoverInfo.getIdentities();
      if (localIterator.hasNext())
      {
        DiscoverInfo.Identity localIdentity = (DiscoverInfo.Identity)localIterator.next();
        return localIdentity.getName();
      }
      return null;
    }
    catch (XMPPException localXMPPException)
    {
      localXMPPException.printStackTrace();
    }
    return null;
  }

  public String getNickname()
  {
    return this.nickname;
  }

  public void changeNickname(String paramString)
    throws XMPPException
  {
    if ((paramString == null) || (paramString.equals("")))
      throw new IllegalArgumentException("Nickname must not be null or blank.");
    if (!this.joined)
      throw new IllegalStateException("Must be logged into the room to change nickname.");
    Presence localPresence1 = new Presence(Presence.Type.available);
    localPresence1.setTo(this.room + "/" + paramString);
    Object localObject2 = this.presenceInterceptors.iterator();
    while (((Iterator)localObject2).hasNext())
    {
      localObject1 = (PacketInterceptor)((Iterator)localObject2).next();
      ((PacketInterceptor)localObject1).interceptPacket(localPresence1);
    }
    Object localObject1 = new AndFilter(new PacketFilter[] { new FromMatchesFilter(this.room + "/" + paramString), new PacketTypeFilter(Presence.class) });
    localObject2 = this.connection.createPacketCollector((PacketFilter)localObject1);
    this.connection.sendPacket(localPresence1);
    Presence localPresence2 = (Presence)((PacketCollector)localObject2).nextResult(SmackConfiguration.getPacketReplyTimeout());
    ((PacketCollector)localObject2).cancel();
    if (localPresence2 == null)
      throw new XMPPException("No response from server.");
    if (localPresence2.getError() != null)
      throw new XMPPException(localPresence2.getError());
    this.nickname = paramString;
  }

  public void changeAvailabilityStatus(String paramString, Presence.Mode paramMode)
  {
    if ((this.nickname == null) || (this.nickname.equals("")))
      throw new IllegalArgumentException("Nickname must not be null or blank.");
    if (!this.joined)
      throw new IllegalStateException("Must be logged into the room to change the availability status.");
    Presence localPresence = new Presence(Presence.Type.available);
    localPresence.setStatus(paramString);
    localPresence.setMode(paramMode);
    localPresence.setTo(this.room + "/" + this.nickname);
    Iterator localIterator = this.presenceInterceptors.iterator();
    while (localIterator.hasNext())
    {
      PacketInterceptor localPacketInterceptor = (PacketInterceptor)localIterator.next();
      localPacketInterceptor.interceptPacket(localPresence);
    }
    this.connection.sendPacket(localPresence);
  }

  public void kickParticipant(String paramString1, String paramString2)
    throws XMPPException
  {
    changeRole(paramString1, "none", paramString2);
  }

  public void grantVoice(Collection<String> paramCollection)
    throws XMPPException
  {
    changeRole(paramCollection, "participant");
  }

  public void grantVoice(String paramString)
    throws XMPPException
  {
    changeRole(paramString, "participant", null);
  }

  public void revokeVoice(Collection<String> paramCollection)
    throws XMPPException
  {
    changeRole(paramCollection, "visitor");
  }

  public void revokeVoice(String paramString)
    throws XMPPException
  {
    changeRole(paramString, "visitor", null);
  }

  public void banUsers(Collection<String> paramCollection)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramCollection, "outcast");
  }

  public void banUser(String paramString1, String paramString2)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramString1, "outcast", paramString2);
  }

  public void grantMembership(Collection<String> paramCollection)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramCollection, "member");
  }

  public void grantMembership(String paramString)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramString, "member", null);
  }

  public void revokeMembership(Collection<String> paramCollection)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramCollection, "none");
  }

  public void revokeMembership(String paramString)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramString, "none", null);
  }

  public void grantModerator(Collection<String> paramCollection)
    throws XMPPException
  {
    changeRole(paramCollection, "moderator");
  }

  public void grantModerator(String paramString)
    throws XMPPException
  {
    changeRole(paramString, "moderator", null);
  }

  public void revokeModerator(Collection<String> paramCollection)
    throws XMPPException
  {
    changeRole(paramCollection, "participant");
  }

  public void revokeModerator(String paramString)
    throws XMPPException
  {
    changeRole(paramString, "participant", null);
  }

  public void grantOwnership(Collection<String> paramCollection)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramCollection, "owner");
  }

  public void grantOwnership(String paramString)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramString, "owner", null);
  }

  public void revokeOwnership(Collection<String> paramCollection)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramCollection, "admin");
  }

  public void revokeOwnership(String paramString)
    throws XMPPException
  {
    changeAffiliationByAdmin(paramString, "admin", null);
  }

  public void grantAdmin(Collection<String> paramCollection)
    throws XMPPException
  {
    changeAffiliationByOwner(paramCollection, "admin");
  }

  public void grantAdmin(String paramString)
    throws XMPPException
  {
    changeAffiliationByOwner(paramString, "admin");
  }

  public void revokeAdmin(Collection<String> paramCollection)
    throws XMPPException
  {
    changeAffiliationByOwner(paramCollection, "member");
  }

  public void revokeAdmin(String paramString)
    throws XMPPException
  {
    changeAffiliationByOwner(paramString, "member");
  }

  private void changeAffiliationByOwner(String paramString1, String paramString2)
    throws XMPPException
  {
    MUCOwner localMUCOwner = new MUCOwner();
    localMUCOwner.setTo(this.room);
    localMUCOwner.setType(IQ.Type.SET);
    MUCOwner.Item localItem = new MUCOwner.Item(paramString2);
    localItem.setJid(paramString1);
    localMUCOwner.addItem(localItem);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localMUCOwner.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localMUCOwner);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
  }

  private void changeAffiliationByOwner(Collection<String> paramCollection, String paramString)
    throws XMPPException
  {
    MUCOwner localMUCOwner = new MUCOwner();
    localMUCOwner.setTo(this.room);
    localMUCOwner.setType(IQ.Type.SET);
    Object localObject2 = paramCollection.iterator();
    while (((Iterator)localObject2).hasNext())
    {
      localObject1 = (String)((Iterator)localObject2).next();
      localObject3 = new MUCOwner.Item(paramString);
      ((MUCOwner.Item)localObject3).setJid((String)localObject1);
      localMUCOwner.addItem((MUCOwner.Item)localObject3);
    }
    Object localObject1 = new PacketIDFilter(localMUCOwner.getPacketID());
    localObject2 = this.connection.createPacketCollector((PacketFilter)localObject1);
    this.connection.sendPacket(localMUCOwner);
    Object localObject3 = (IQ)((PacketCollector)localObject2).nextResult(SmackConfiguration.getPacketReplyTimeout());
    ((PacketCollector)localObject2).cancel();
    if (localObject3 == null)
      throw new XMPPException("No response from server.");
    if (((IQ)localObject3).getError() != null)
      throw new XMPPException(((IQ)localObject3).getError());
  }

  private void changeAffiliationByAdmin(String paramString1, String paramString2, String paramString3)
    throws XMPPException
  {
    MUCAdmin localMUCAdmin = new MUCAdmin();
    localMUCAdmin.setTo(this.room);
    localMUCAdmin.setType(IQ.Type.SET);
    MUCAdmin.Item localItem = new MUCAdmin.Item(paramString2, null);
    localItem.setJid(paramString1);
    if (paramString3 != null)
      localItem.setReason(paramString3);
    localMUCAdmin.addItem(localItem);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localMUCAdmin.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localMUCAdmin);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
  }

  private void changeAffiliationByAdmin(Collection<String> paramCollection, String paramString)
    throws XMPPException
  {
    MUCAdmin localMUCAdmin = new MUCAdmin();
    localMUCAdmin.setTo(this.room);
    localMUCAdmin.setType(IQ.Type.SET);
    Object localObject2 = paramCollection.iterator();
    while (((Iterator)localObject2).hasNext())
    {
      localObject1 = (String)((Iterator)localObject2).next();
      localObject3 = new MUCAdmin.Item(paramString, null);
      ((MUCAdmin.Item)localObject3).setJid((String)localObject1);
      localMUCAdmin.addItem((MUCAdmin.Item)localObject3);
    }
    Object localObject1 = new PacketIDFilter(localMUCAdmin.getPacketID());
    localObject2 = this.connection.createPacketCollector((PacketFilter)localObject1);
    this.connection.sendPacket(localMUCAdmin);
    Object localObject3 = (IQ)((PacketCollector)localObject2).nextResult(SmackConfiguration.getPacketReplyTimeout());
    ((PacketCollector)localObject2).cancel();
    if (localObject3 == null)
      throw new XMPPException("No response from server.");
    if (((IQ)localObject3).getError() != null)
      throw new XMPPException(((IQ)localObject3).getError());
  }

  private void changeRole(String paramString1, String paramString2, String paramString3)
    throws XMPPException
  {
    MUCAdmin localMUCAdmin = new MUCAdmin();
    localMUCAdmin.setTo(this.room);
    localMUCAdmin.setType(IQ.Type.SET);
    MUCAdmin.Item localItem = new MUCAdmin.Item(null, paramString2);
    localItem.setNick(paramString1);
    localItem.setReason(paramString3);
    localMUCAdmin.addItem(localItem);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localMUCAdmin.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localMUCAdmin);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
  }

  private void changeRole(Collection<String> paramCollection, String paramString)
    throws XMPPException
  {
    MUCAdmin localMUCAdmin = new MUCAdmin();
    localMUCAdmin.setTo(this.room);
    localMUCAdmin.setType(IQ.Type.SET);
    Object localObject2 = paramCollection.iterator();
    while (((Iterator)localObject2).hasNext())
    {
      localObject1 = (String)((Iterator)localObject2).next();
      localObject3 = new MUCAdmin.Item(null, paramString);
      ((MUCAdmin.Item)localObject3).setNick((String)localObject1);
      localMUCAdmin.addItem((MUCAdmin.Item)localObject3);
    }
    Object localObject1 = new PacketIDFilter(localMUCAdmin.getPacketID());
    localObject2 = this.connection.createPacketCollector((PacketFilter)localObject1);
    this.connection.sendPacket(localMUCAdmin);
    Object localObject3 = (IQ)((PacketCollector)localObject2).nextResult(SmackConfiguration.getPacketReplyTimeout());
    ((PacketCollector)localObject2).cancel();
    if (localObject3 == null)
      throw new XMPPException("No response from server.");
    if (((IQ)localObject3).getError() != null)
      throw new XMPPException(((IQ)localObject3).getError());
  }

  public int getOccupantsCount()
  {
    return this.occupantsMap.size();
  }

  public Iterator<String> getOccupants()
  {
    return Collections.unmodifiableList(new ArrayList(this.occupantsMap.keySet())).iterator();
  }

  public Presence getOccupantPresence(String paramString)
  {
    return (Presence)this.occupantsMap.get(paramString);
  }

  public Occupant getOccupant(String paramString)
  {
    Presence localPresence = (Presence)this.occupantsMap.get(paramString);
    if (localPresence != null)
      return new Occupant(localPresence);
    return null;
  }

  public void addParticipantListener(PacketListener paramPacketListener)
  {
    this.connection.addPacketListener(paramPacketListener, this.presenceFilter);
    this.connectionListeners.add(paramPacketListener);
  }

  public void removeParticipantListener(PacketListener paramPacketListener)
  {
    this.connection.removePacketListener(paramPacketListener);
    this.connectionListeners.remove(paramPacketListener);
  }

  public Collection<Affiliate> getOwners()
    throws XMPPException
  {
    return getAffiliatesByAdmin("owner");
  }

  public Collection<Affiliate> getAdmins()
    throws XMPPException
  {
    return getAffiliatesByOwner("admin");
  }

  public Collection<Affiliate> getMembers()
    throws XMPPException
  {
    return getAffiliatesByAdmin("member");
  }

  public Collection<Affiliate> getOutcasts()
    throws XMPPException
  {
    return getAffiliatesByAdmin("outcast");
  }

  private Collection<Affiliate> getAffiliatesByOwner(String paramString)
    throws XMPPException
  {
    MUCOwner localMUCOwner1 = new MUCOwner();
    localMUCOwner1.setTo(this.room);
    localMUCOwner1.setType(IQ.Type.GET);
    MUCOwner.Item localItem = new MUCOwner.Item(paramString);
    localMUCOwner1.addItem(localItem);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localMUCOwner1.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localMUCOwner1);
    MUCOwner localMUCOwner2 = (MUCOwner)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localMUCOwner2 == null)
      throw new XMPPException("No response from server.");
    if (localMUCOwner2.getError() != null)
      throw new XMPPException(localMUCOwner2.getError());
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = localMUCOwner2.getItems();
    while (localIterator.hasNext())
      localArrayList.add(new Affiliate((MUCOwner.Item)localIterator.next()));
    return localArrayList;
  }

  private Collection<Affiliate> getAffiliatesByAdmin(String paramString)
    throws XMPPException
  {
    MUCAdmin localMUCAdmin1 = new MUCAdmin();
    localMUCAdmin1.setTo(this.room);
    localMUCAdmin1.setType(IQ.Type.GET);
    MUCAdmin.Item localItem = new MUCAdmin.Item(paramString, null);
    localMUCAdmin1.addItem(localItem);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localMUCAdmin1.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localMUCAdmin1);
    MUCAdmin localMUCAdmin2 = (MUCAdmin)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localMUCAdmin2 == null)
      throw new XMPPException("No response from server.");
    if (localMUCAdmin2.getError() != null)
      throw new XMPPException(localMUCAdmin2.getError());
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = localMUCAdmin2.getItems();
    while (localIterator.hasNext())
      localArrayList.add(new Affiliate((MUCAdmin.Item)localIterator.next()));
    return localArrayList;
  }

  public Collection<Occupant> getModerators()
    throws XMPPException
  {
    return getOccupants("moderator");
  }

  public Collection<Occupant> getParticipants()
    throws XMPPException
  {
    return getOccupants("participant");
  }

  private Collection<Occupant> getOccupants(String paramString)
    throws XMPPException
  {
    MUCAdmin localMUCAdmin1 = new MUCAdmin();
    localMUCAdmin1.setTo(this.room);
    localMUCAdmin1.setType(IQ.Type.GET);
    MUCAdmin.Item localItem = new MUCAdmin.Item(null, paramString);
    localMUCAdmin1.addItem(localItem);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localMUCAdmin1.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localMUCAdmin1);
    MUCAdmin localMUCAdmin2 = (MUCAdmin)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localMUCAdmin2 == null)
      throw new XMPPException("No response from server.");
    if (localMUCAdmin2.getError() != null)
      throw new XMPPException(localMUCAdmin2.getError());
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = localMUCAdmin2.getItems();
    while (localIterator.hasNext())
      localArrayList.add(new Occupant((MUCAdmin.Item)localIterator.next()));
    return localArrayList;
  }

  public void sendMessage(String paramString)
    throws XMPPException
  {
    Message localMessage = new Message(this.room, Message.Type.groupchat);
    localMessage.setBody(paramString);
    this.connection.sendPacket(localMessage);
  }

  public Chat createPrivateChat(String paramString, MessageListener paramMessageListener)
  {
    return this.connection.getChatManager().createChat(paramString, paramMessageListener);
  }

  public Message createMessage()
  {
    return new Message(this.room, Message.Type.groupchat);
  }

  public void sendMessage(Message paramMessage)
    throws XMPPException
  {
    this.connection.sendPacket(paramMessage);
  }

  public Message pollMessage()
  {
    return (Message)this.messageCollector.pollResult();
  }

  public Message nextMessage()
  {
    return (Message)this.messageCollector.nextResult();
  }

  public Message nextMessage(long paramLong)
  {
    return (Message)this.messageCollector.nextResult(paramLong);
  }

  public void addMessageListener(PacketListener paramPacketListener)
  {
    this.connection.addPacketListener(paramPacketListener, this.messageFilter);
    this.connectionListeners.add(paramPacketListener);
  }

  public void removeMessageListener(PacketListener paramPacketListener)
  {
    this.connection.removePacketListener(paramPacketListener);
    this.connectionListeners.remove(paramPacketListener);
  }

  public void changeSubject(final String paramString)
    throws XMPPException
  {
    Message localMessage1 = new Message(this.room, Message.Type.groupchat);
    localMessage1.setSubject(paramString);
    AndFilter localAndFilter = new AndFilter(new PacketFilter[] { new FromMatchesFilter(this.room), new PacketTypeFilter(Message.class) });
    localAndFilter = new AndFilter(new PacketFilter[] { localAndFilter, new PacketFilter()
    {
      public boolean accept(Packet paramAnonymousPacket)
      {
        Message localMessage = (Message)paramAnonymousPacket;
        return paramString.equals(localMessage.getSubject());
      }
    }
     });
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localAndFilter);
    this.connection.sendPacket(localMessage1);
    Message localMessage2 = (Message)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localMessage2 == null)
      throw new XMPPException("No response from server.");
    if (localMessage2.getError() != null)
      throw new XMPPException(localMessage2.getError());
  }

  private synchronized void userHasJoined()
  {
    Object localObject = (List)joinedRooms.get(this.connection);
    if (localObject == null)
    {
      localObject = new ArrayList();
      joinedRooms.put(this.connection, localObject);
    }
    ((List)localObject).add(this.room);
  }

  private synchronized void userHasLeft()
  {
    List localList = (List)joinedRooms.get(this.connection);
    if (localList == null)
      return;
    localList.remove(this.room);
    cleanup();
  }

  private MUCUser getMUCUserExtension(Packet paramPacket)
  {
    if (paramPacket != null)
      return (MUCUser)paramPacket.getExtension("x", "http://jabber.org/protocol/muc#user");
    return null;
  }

  public void addUserStatusListener(UserStatusListener paramUserStatusListener)
  {
    synchronized (this.userStatusListeners)
    {
      if (!this.userStatusListeners.contains(paramUserStatusListener))
        this.userStatusListeners.add(paramUserStatusListener);
    }
  }

  public void removeUserStatusListener(UserStatusListener paramUserStatusListener)
  {
    synchronized (this.userStatusListeners)
    {
      this.userStatusListeners.remove(paramUserStatusListener);
    }
  }

  private void fireUserStatusListeners(String paramString, Object[] paramArrayOfObject)
  {
    UserStatusListener[] arrayOfUserStatusListener1;
    synchronized (this.userStatusListeners)
    {
      arrayOfUserStatusListener1 = new UserStatusListener[this.userStatusListeners.size()];
      this.userStatusListeners.toArray(arrayOfUserStatusListener1);
    }
    ??? = new Class[paramArrayOfObject.length];
    for (int i = 0; i < paramArrayOfObject.length; i++)
      ???[i] = paramArrayOfObject[i].getClass();
    try
    {
      Method localMethod = UserStatusListener.class.getDeclaredMethod(paramString, (Class[])???);
      for (UserStatusListener localUserStatusListener : arrayOfUserStatusListener1)
        localMethod.invoke(localUserStatusListener, paramArrayOfObject);
    }
    catch (NoSuchMethodException localNoSuchMethodException)
    {
      localNoSuchMethodException.printStackTrace();
    }
    catch (InvocationTargetException localInvocationTargetException)
    {
      localInvocationTargetException.printStackTrace();
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      localIllegalAccessException.printStackTrace();
    }
  }

  public void addParticipantStatusListener(ParticipantStatusListener paramParticipantStatusListener)
  {
    synchronized (this.participantStatusListeners)
    {
      if (!this.participantStatusListeners.contains(paramParticipantStatusListener))
        this.participantStatusListeners.add(paramParticipantStatusListener);
    }
  }

  public void removeParticipantStatusListener(ParticipantStatusListener paramParticipantStatusListener)
  {
    synchronized (this.participantStatusListeners)
    {
      this.participantStatusListeners.remove(paramParticipantStatusListener);
    }
  }

  private void fireParticipantStatusListeners(String paramString, List<String> paramList)
  {
    ParticipantStatusListener[] arrayOfParticipantStatusListener1;
    synchronized (this.participantStatusListeners)
    {
      arrayOfParticipantStatusListener1 = new ParticipantStatusListener[this.participantStatusListeners.size()];
      this.participantStatusListeners.toArray(arrayOfParticipantStatusListener1);
    }
    try
    {
      ??? = new Class[paramList.size()];
      for (int i = 0; i < paramList.size(); i++)
        ???[i] = String.class;
      Method localMethod = ParticipantStatusListener.class.getDeclaredMethod(paramString, (Class[])???);
      for (ParticipantStatusListener localParticipantStatusListener : arrayOfParticipantStatusListener1)
        localMethod.invoke(localParticipantStatusListener, paramList.toArray());
    }
    catch (NoSuchMethodException localNoSuchMethodException)
    {
      localNoSuchMethodException.printStackTrace();
    }
    catch (InvocationTargetException localInvocationTargetException)
    {
      localInvocationTargetException.printStackTrace();
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      localIllegalAccessException.printStackTrace();
    }
  }

  private void init()
  {
    this.messageFilter = new AndFilter(new PacketFilter[] { new FromMatchesFilter(this.room), new MessageTypeFilter(Message.Type.groupchat) });
    this.messageFilter = new AndFilter(new PacketFilter[] { this.messageFilter, new PacketFilter()
    {
      public boolean accept(Packet paramAnonymousPacket)
      {
        Message localMessage = (Message)paramAnonymousPacket;
        return localMessage.getBody() != null;
      }
    }
     });
    this.presenceFilter = new AndFilter(new PacketFilter[] { new FromMatchesFilter(this.room), new PacketTypeFilter(Presence.class) });
    this.messageCollector = new ConnectionDetachedPacketCollector();
    PacketListener local4 = new PacketListener()
    {
      public void processPacket(Packet paramAnonymousPacket)
      {
        Message localMessage = (Message)paramAnonymousPacket;
        MultiUserChat.this.subject = localMessage.getSubject();
        MultiUserChat.this.fireSubjectUpdatedListeners(localMessage.getSubject(), localMessage.getFrom());
      }
    };
    PacketListener local5 = new PacketListener()
    {
      public void processPacket(Packet paramAnonymousPacket)
      {
        Presence localPresence = (Presence)paramAnonymousPacket;
        String str1 = localPresence.getFrom();
        String str2 = MultiUserChat.this.room + "/" + MultiUserChat.this.nickname;
        boolean bool = localPresence.getFrom().equals(str2);
        Object localObject1;
        Object localObject2;
        if (localPresence.getType() == Presence.Type.available)
        {
          localObject1 = (Presence)MultiUserChat.this.occupantsMap.put(str1, localPresence);
          if (localObject1 != null)
          {
            localObject2 = MultiUserChat.this.getMUCUserExtension((Packet)localObject1);
            String str3 = ((MUCUser)localObject2).getItem().getAffiliation();
            String str4 = ((MUCUser)localObject2).getItem().getRole();
            localObject2 = MultiUserChat.this.getMUCUserExtension(localPresence);
            String str5 = ((MUCUser)localObject2).getItem().getAffiliation();
            String str6 = ((MUCUser)localObject2).getItem().getRole();
            MultiUserChat.this.checkRoleModifications(str4, str6, bool, str1);
            MultiUserChat.this.checkAffiliationModifications(str3, str5, bool, str1);
          }
          else if (!bool)
          {
            localObject2 = new ArrayList();
            ((List)localObject2).add(str1);
            MultiUserChat.this.fireParticipantStatusListeners("joined", (List)localObject2);
          }
        }
        else if (localPresence.getType() == Presence.Type.unavailable)
        {
          MultiUserChat.this.occupantsMap.remove(str1);
          localObject1 = MultiUserChat.this.getMUCUserExtension(localPresence);
          if ((localObject1 != null) && (((MUCUser)localObject1).getStatus() != null))
          {
            MultiUserChat.this.checkPresenceCode(((MUCUser)localObject1).getStatus().getCode(), localPresence.getFrom().equals(str2), (MUCUser)localObject1, str1);
          }
          else if (!bool)
          {
            localObject2 = new ArrayList();
            ((List)localObject2).add(str1);
            MultiUserChat.this.fireParticipantStatusListeners("left", (List)localObject2);
          }
        }
      }
    };
    PacketListener local6 = new PacketListener()
    {
      public void processPacket(Packet paramAnonymousPacket)
      {
        MUCUser localMUCUser = MultiUserChat.this.getMUCUserExtension(paramAnonymousPacket);
        if ((localMUCUser.getDecline() != null) && (((Message)paramAnonymousPacket).getType() != Message.Type.error))
          MultiUserChat.this.fireInvitationRejectionListeners(localMUCUser.getDecline().getFrom(), localMUCUser.getDecline().getReason());
      }
    };
    PacketMultiplexListener localPacketMultiplexListener = new PacketMultiplexListener(this.messageCollector, local5, local4, local6);
    this.roomListenerMultiplexor = RoomListenerMultiplexor.getRoomMultiplexor(this.connection);
    this.roomListenerMultiplexor.addRoom(this.room, localPacketMultiplexListener);
  }

  private void checkRoleModifications(String paramString1, String paramString2, boolean paramBoolean, String paramString3)
  {
    ArrayList localArrayList;
    if ((("visitor".equals(paramString1)) || ("none".equals(paramString1))) && ("participant".equals(paramString2)))
    {
      if (paramBoolean)
      {
        fireUserStatusListeners("voiceGranted", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("voiceGranted", localArrayList);
      }
    }
    else if (("participant".equals(paramString1)) && (("visitor".equals(paramString2)) || ("none".equals(paramString2))))
      if (paramBoolean)
      {
        fireUserStatusListeners("voiceRevoked", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("voiceRevoked", localArrayList);
      }
    if ((!"moderator".equals(paramString1)) && ("moderator".equals(paramString2)))
    {
      if (("visitor".equals(paramString1)) || ("none".equals(paramString1)))
        if (paramBoolean)
        {
          fireUserStatusListeners("voiceGranted", new Object[0]);
        }
        else
        {
          localArrayList = new ArrayList();
          localArrayList.add(paramString3);
          fireParticipantStatusListeners("voiceGranted", localArrayList);
        }
      if (paramBoolean)
      {
        fireUserStatusListeners("moderatorGranted", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("moderatorGranted", localArrayList);
      }
    }
    else if (("moderator".equals(paramString1)) && (!"moderator".equals(paramString2)))
    {
      if (("visitor".equals(paramString2)) || ("none".equals(paramString2)))
        if (paramBoolean)
        {
          fireUserStatusListeners("voiceRevoked", new Object[0]);
        }
        else
        {
          localArrayList = new ArrayList();
          localArrayList.add(paramString3);
          fireParticipantStatusListeners("voiceRevoked", localArrayList);
        }
      if (paramBoolean)
      {
        fireUserStatusListeners("moderatorRevoked", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("moderatorRevoked", localArrayList);
      }
    }
  }

  private void checkAffiliationModifications(String paramString1, String paramString2, boolean paramBoolean, String paramString3)
  {
    ArrayList localArrayList;
    if (("owner".equals(paramString1)) && (!"owner".equals(paramString2)))
    {
      if (paramBoolean)
      {
        fireUserStatusListeners("ownershipRevoked", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("ownershipRevoked", localArrayList);
      }
    }
    else if (("admin".equals(paramString1)) && (!"admin".equals(paramString2)))
    {
      if (paramBoolean)
      {
        fireUserStatusListeners("adminRevoked", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("adminRevoked", localArrayList);
      }
    }
    else if (("member".equals(paramString1)) && (!"member".equals(paramString2)))
      if (paramBoolean)
      {
        fireUserStatusListeners("membershipRevoked", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("membershipRevoked", localArrayList);
      }
    if ((!"owner".equals(paramString1)) && ("owner".equals(paramString2)))
    {
      if (paramBoolean)
      {
        fireUserStatusListeners("ownershipGranted", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("ownershipGranted", localArrayList);
      }
    }
    else if ((!"admin".equals(paramString1)) && ("admin".equals(paramString2)))
    {
      if (paramBoolean)
      {
        fireUserStatusListeners("adminGranted", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("adminGranted", localArrayList);
      }
    }
    else if ((!"member".equals(paramString1)) && ("member".equals(paramString2)))
      if (paramBoolean)
      {
        fireUserStatusListeners("membershipGranted", new Object[0]);
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString3);
        fireParticipantStatusListeners("membershipGranted", localArrayList);
      }
  }

  private void checkPresenceCode(String paramString1, boolean paramBoolean, MUCUser paramMUCUser, String paramString2)
  {
    ArrayList localArrayList;
    if ("307".equals(paramString1))
    {
      if (paramBoolean)
      {
        this.joined = false;
        fireUserStatusListeners("kicked", new Object[] { paramMUCUser.getItem().getActor(), paramMUCUser.getItem().getReason() });
        this.occupantsMap.clear();
        this.nickname = null;
        userHasLeft();
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString2);
        localArrayList.add(paramMUCUser.getItem().getActor());
        localArrayList.add(paramMUCUser.getItem().getReason());
        fireParticipantStatusListeners("kicked", localArrayList);
      }
    }
    else if ("301".equals(paramString1))
    {
      if (paramBoolean)
      {
        this.joined = false;
        fireUserStatusListeners("banned", new Object[] { paramMUCUser.getItem().getActor(), paramMUCUser.getItem().getReason() });
        this.occupantsMap.clear();
        this.nickname = null;
        userHasLeft();
      }
      else
      {
        localArrayList = new ArrayList();
        localArrayList.add(paramString2);
        localArrayList.add(paramMUCUser.getItem().getActor());
        localArrayList.add(paramMUCUser.getItem().getReason());
        fireParticipantStatusListeners("banned", localArrayList);
      }
    }
    else if ("321".equals(paramString1))
    {
      if (paramBoolean)
      {
        this.joined = false;
        fireUserStatusListeners("membershipRevoked", new Object[0]);
        this.occupantsMap.clear();
        this.nickname = null;
        userHasLeft();
      }
    }
    else if ("303".equals(paramString1))
    {
      localArrayList = new ArrayList();
      localArrayList.add(paramString2);
      localArrayList.add(paramMUCUser.getItem().getNick());
      fireParticipantStatusListeners("nicknameChanged", localArrayList);
    }
  }

  private void cleanup()
  {
    try
    {
      if (this.connection != null)
      {
        this.roomListenerMultiplexor.removeRoom(this.room);
        Iterator localIterator = this.connectionListeners.iterator();
        while (localIterator.hasNext())
        {
          PacketListener localPacketListener = (PacketListener)localIterator.next();
          this.connection.removePacketListener(localPacketListener);
        }
      }
    }
    catch (Exception localException)
    {
    }
  }

  protected void finalize()
    throws Throwable
  {
    cleanup();
    super.finalize();
  }

  private static class InvitationsMonitor
    implements ConnectionListener
  {
    private static final Map<Connection, WeakReference<InvitationsMonitor>> monitors = new WeakHashMap();
    private final List<InvitationListener> invitationsListeners = new ArrayList();
    private Connection connection;
    private PacketFilter invitationFilter;
    private PacketListener invitationPacketListener;

    public static InvitationsMonitor getInvitationsMonitor(Connection paramConnection)
    {
      synchronized (monitors)
      {
        if ((!monitors.containsKey(paramConnection)) || (((WeakReference)monitors.get(paramConnection)).get() == null))
        {
          EMLog.d("InvitationsMonitor", "create a new monitor");
          InvitationsMonitor localInvitationsMonitor = new InvitationsMonitor(paramConnection);
          monitors.put(paramConnection, new WeakReference(localInvitationsMonitor));
          return localInvitationsMonitor;
        }
        return (InvitationsMonitor)((WeakReference)monitors.get(paramConnection)).get();
      }
    }

    private InvitationsMonitor(Connection paramConnection)
    {
      this.connection = paramConnection;
    }

    public void addInvitationListener(InvitationListener paramInvitationListener)
    {
      synchronized (this.invitationsListeners)
      {
        if (this.invitationsListeners.size() == 0)
          init();
        if (!this.invitationsListeners.contains(paramInvitationListener))
          this.invitationsListeners.add(paramInvitationListener);
      }
    }

    public void removeInvitationListener(InvitationListener paramInvitationListener)
    {
      synchronized (this.invitationsListeners)
      {
        if (this.invitationsListeners.contains(paramInvitationListener))
          this.invitationsListeners.remove(paramInvitationListener);
        if (this.invitationsListeners.size() == 0)
          cancel();
      }
    }

    private void fireInvitationListeners(String paramString1, String paramString2, String paramString3, String paramString4, Message paramMessage)
    {
      InvitationListener[] arrayOfInvitationListener1;
      synchronized (this.invitationsListeners)
      {
        arrayOfInvitationListener1 = new InvitationListener[this.invitationsListeners.size()];
        this.invitationsListeners.toArray(arrayOfInvitationListener1);
      }
      for (??? : arrayOfInvitationListener1)
        ???.invitationReceived(this.connection, paramString1, paramString2, paramString3, paramString4, paramMessage);
    }

    public void connectionClosed()
    {
      cancel();
    }

    public void connectionClosedOnError(Exception paramException)
    {
    }

    public void reconnectingIn(int paramInt)
    {
    }

    public void reconnectionSuccessful()
    {
    }

    public void reconnectionFailed(Exception paramException)
    {
    }

    private void init()
    {
      this.invitationFilter = new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
      this.invitationPacketListener = new PacketListener()
      {
        public void processPacket(Packet paramAnonymousPacket)
        {
          MUCUser localMUCUser = (MUCUser)paramAnonymousPacket.getExtension("x", "http://jabber.org/protocol/muc#user");
          if ((localMUCUser.getInvite() != null) && (((Message)paramAnonymousPacket).getType() != Message.Type.error))
            MultiUserChat.InvitationsMonitor.this.fireInvitationListeners(paramAnonymousPacket.getFrom(), localMUCUser.getInvite().getFrom(), localMUCUser.getInvite().getReason(), localMUCUser.getPassword(), (Message)paramAnonymousPacket);
        }
      };
      this.connection.addPacketListener(this.invitationPacketListener, this.invitationFilter);
      this.connection.addConnectionListener(this);
    }

    private void cancel()
    {
      EMLog.d("InvitationsMonitor", "invitationPacketListener = " + this.invitationPacketListener);
      if (this.invitationPacketListener != null)
        this.connection.removePacketListener(this.invitationPacketListener);
      this.connection.removeConnectionListener(this);
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smackx.muc.MultiUserChat
 * JD-Core Version:    0.6.1
 */